//
//  ClubGamesSearchView.swift
//  77Club
//
//  Created by Apple on 2024/9/13.
//

import UIKit
import Cosmos

class ClubGamesSearchCell: UICollectionViewCell {

    private let bgView = c_make_ex(UIView.self)
        .bgColor("#F2F3F5").corner(12).end()
    private let nameLabel = c_make_ex(UILabel.self)
        .color("#2E3033").font(12.font_medium).alignment(.center).end()
    
    var model: ClubHomeGamesSearchModel?{
        didSet{
            guard let md = model else { return }
            nameLabel.text = md.name
        }
    }
    var titleString: String = ""{
        didSet{
            nameLabel.text = titleString
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.backgroundColor = "#F7F8FA".toColor
        backgroundColor = "#F7F8FA".toColor
        
        contentView.subviews{
            bgView
            nameLabel
        }
        
        bgView.fillContainer()
        nameLabel.leading(0).trailing(0).centerHorizontally().centerVertically()
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}


//MARK: 榜单列表
class ClubGamesSearchListCell: UITableViewCell {
    
    private let iconImageV = c_make_ex(UIImageView.self)
        .corner(12.0.Scale).mode(.scaleAspectFill).end()
    private let nameLabel = c_make_ex(UILabel.self)
        .color(.black).font(14.font_semiBold).end()
    private let tagLabel = c_make_ex(UILabel.self)
        .bgColor("#E55C67".toColor.alpha(0.1)).font(8.font_medium)
        .corner(4.0.Scale).color("#E55C67").end()
    private let subLabel = c_make_ex(UILabel.self)
        .color("#AEB0B3").font(13.font_semiBold).end()
    private var starView = CosmosView()
    private let scoreLabel = c_make_ex(UILabel.self)
        .color("#FF7500").font(14.font_wide).end()
    private let infoLabel = c_make_ex(UILabel.self)
        .color("#FF7500").font(12.font_medium)
        .text("详情").alignment(.center).corner(14.0.Scale)
        .bgColor("#FF7500".toColor.alpha(0.08)).end()

    var model: ClubNewHomeGameModel? {
        didSet{
            guard let md = model else { return }
            
            iconImageV.loadImage(url: md.icon)
            nameLabel.text = md.name
            let tagStr = md.biaoqian.joined(separator: " · ")
            subLabel.text = tagStr
            starView.rating = Double(md.point/2)
            scoreLabel.text = "\(md.point)"
            if md.pay.count > 0 {
                tagLabel.isHidden = false
                tagLabel.text = " " + md.pay + " "
            }else{
                tagLabel.isHidden = true
            }
        }
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        
        contentView.subviews{
            iconImageV
            nameLabel
            tagLabel
            subLabel
            starView
            scoreLabel
            infoLabel
        }
        
        iconImageV.leading(24.0.Scale).size(60.0.Scale).centerVertically()
        nameLabel.leading(96.0.Scale).top(14.0.Scale).width(<=140)
        tagLabel.height(15.0.Scale)
        tagLabel.Leading == nameLabel.Trailing + 3.0.Scale
        tagLabel.CenterY == nameLabel.CenterY
        subLabel.leading(96.0.Scale).trailing(95.0.Scale)
        subLabel.Top == nameLabel.Bottom + 2.0.Scale
        starView.leading(96.0.Scale).height(12.0.Scale).width(68.0.Scale)
        starView.Bottom == iconImageV.Bottom - 2.0.Scale
        scoreLabel.CenterY == starView.CenterY
        scoreLabel.Leading == starView.Trailing + 4.0.Scale
        infoLabel.trailing(24.0.Scale).width(60.0.Scale).height(28.0.Scale).centerVertically()
        
        starView.rating = 0
        starView.settings.starSize = 12.0.Scale
        starView.settings.starMargin = 2.0.Scale
        starView.settings.fillMode = .half
        starView.settings.emptyImage = "Common_emptyStar".toImage
        starView.settings.filledImage = "Common_fillStar".toImage
        starView.isUserInteractionEnabled = false
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
